package com.example.Filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
//拦截所有的请求
@WebFilter(urlPatterns = "/*")
//@Component
public class DemoFilter implements Filter {

    //    初始化 不用重写 已经被初始化好了  只调用一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init 初始化了一次");
    }

    //拦截  只需处理这个方法即可
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("拦截到了请求");
        filterChain.doFilter(servletRequest,servletResponse);
    }

    //    销毁 同上 不用重写  只调用一次
    @Override
    public void destroy() {
        System.out.println("destroy 关闭了");
    }
}
